package com.zwb.demo.easyweb.modules.config.controller;

import com.zwb.demo.easyweb.common.entity.response.ResponseResult;
import com.zwb.demo.easyweb.modules.config.service.JdbcFieldService;
import com.zwb.demo.easyweb.modules.config.vo.JdbcFieldTypeVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@Api(value = "数据库字段管理接口" ,description = "数据库字段管理接口")
public class JdbcFieldController {

    private final JdbcFieldService jdbcFieldService;


    @Autowired
    public JdbcFieldController(JdbcFieldService jdbcFieldService) {
        this.jdbcFieldService = jdbcFieldService;
    }

    @GetMapping("/config/jdbcField")
    @ApiOperation(value = "查询所有字段类型")
    public ResponseResult findAll(){
        return jdbcFieldService.findAll();
    }

    @GetMapping("/config/database/{databaseType}/jdbcField")
    @ApiOperation(value = "通过数据库类型查询所有字段类型")
    public ResponseResult findAllByDatabaseType(@PathVariable Integer databaseType){
        return jdbcFieldService.findAllByDatabaseType(databaseType);
    }

    @PutMapping("/config/jdbcField")
    @ApiOperation(value = "新增或修改字段类型")
    public ResponseResult addOne(@RequestBody JdbcFieldTypeVO vo){
        return jdbcFieldService.addOrUpdateOne(vo);
    }

    @DeleteMapping("/config/jdbcField/{uuid}")
    @ApiOperation(value = "删除字段类型")
    public ResponseResult deleteOne(@PathVariable String uuid){
        return jdbcFieldService.deleteOne(uuid);
    }

}
